package com.ys.day31.p3FastJson;

import com.alibaba.fastjson.JSON;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * 描述: json 对象 实体化
 *{"car":{"brand":"benz","color":"red"},"courseList":[{"courseName":"语文","score":31},
 * {"courseName":"数学","score":51},{"courseName":"英语","score":61},{"courseName":"物理","score":71},
 * {"courseName":"化学","score":81}],"hobbys":["football,basketball,tennis"],"id":931,"stuSmoking":false}
 * @author CodeYang
 * @version 2021/1/19 0:06
 */
public class Student {

    // 1Car car
    private  Car car;
    //2
    private List<Course> courseList;

    // 3
    private List<String> hobbys;

    private int id;

    private boolean stuSmoking;

    public Student() {
    }

    public Student(Car car, List<Course> courseList, List<String> hobbys, int id, boolean stuSmoking) {
        this.car = car;
        this.courseList = courseList;
        this.hobbys = hobbys;
        this.id = id;
        this.stuSmoking = stuSmoking;
    }

    public Car getCar() {
        return car;
    }

    public void setCar(Car car) {
        this.car = car;
    }

    public List<Course> getCourseList() {
        return courseList;
    }

    public void setCourseList(List<Course> courseList) {
        this.courseList = courseList;
    }

    public List<String> getHobbys() {
        return hobbys;
    }

    public void setHobbys(List<String> hobbys) {
        this.hobbys = hobbys;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public boolean isStuSmoking() {
        return stuSmoking;
    }

    public void setStuSmoking(boolean stuSmoking) {
        this.stuSmoking = stuSmoking;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return id == student.id &&
                stuSmoking == student.stuSmoking &&
                Objects.equals(car, student.car) &&
                Objects.equals(courseList, student.courseList) &&
                Objects.equals(hobbys, student.hobbys);
    }

    @Override
    public int hashCode() {
        return Objects.hash(car, courseList, hobbys, id, stuSmoking);
    }

    @Override
    public String toString() {
        return "Student{" +
                "car=" + car +
                ", courseList=" + courseList +
                ", hobbys=" + hobbys +
                ", id=" + id +
                ", stuSmoking=" + stuSmoking +
                '}';
    }
}



class Course {

    private String courseName;

    private int score;

    public Course() {
    }

    public Course(String courseName, int score) {
        this.courseName = courseName;
        this.score = score;
    }

    public String getCourseName() {
        return courseName;
    }

    public void setCourseName(String courseName) {
        this.courseName = courseName;
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }

    @Override
    public String toString() {
        return "Course{" +
                "courseName='" + courseName + '\'' +
                ", score=" + score +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Course course = (Course) o;
        return score == course.score &&
                Objects.equals(courseName, course.courseName);
    }

    @Override
    public int hashCode() {
        return Objects.hash(courseName, score);
    }
}


class  Car {
    private String brand;

    private String color;

    public Car() {
    }

    public Car(String brand, String color) {
        this.brand = brand;
        this.color = color;
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    @Override
    public String toString() {
        return "Car{" +
                "brand='" + brand + '\'' +
                ", color='" + color + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Car car = (Car) o;
        return Objects.equals(brand, car.brand) &&
                Objects.equals(color, car.color);
    }

    @Override
    public int hashCode() {
        return Objects.hash(brand, color);
    }

    public static void main(String[] args) {
        Student student = new Student();
        student.setId(1);
        student.setStuSmoking(false);
        student.setCar(new Car("BWM","red"));
        student.setCourseList(Arrays.asList(new Course("it",1)));
        student.setHobbys(Arrays.asList("c++"));
        String s = JSON.toJSONString(student);
        System.out.println(s);
    }
}
